package com.seminario.spring.dao.caralibro;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.seminario.spring.dao.DAOImpl;
import com.seminario.spring.domain.Amistad;
@Repository
public class AmistadDAOImpl extends DAOImpl<Amistad> implements AmistadDAO {

	@Override
	protected Class<Amistad> getEntityClass() {
		
		return Amistad.class;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Amistad> getAll() {
		String query = "Select a From Amistad a";
		List<Amistad> list = (List<Amistad>) entityManager.createQuery(query);
		return list;
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public List<Amistad> getAmistadPorPerfilId(Integer PerfilId) {
		String query = "SELECT a FROM Amistad a WHERE a.amistadPK.perfilId = :perfil1 OR a.amistadPK.amigosId = :perfil2";
		List resultList = entityManager.createQuery(query).setParameter("perfil1", PerfilId).setParameter("perfil2", PerfilId).getResultList();
		List<Amistad> amistads= new ArrayList<Amistad>();
		if(resultList!=null){
			amistads = (List<Amistad>) resultList;
		}
		return amistads;
	}

}
